<template>
	<view class="phone-consult">
		<common-navbar title="电话咨询" />
		<topBg />
		<view class="consult-top">
			<view class="consult-name">
				电话咨询
			</view>
			<view class="consult-price">
				{{userInfo?userInfo.vip>0?'会员免支付':`￥${price}`:`￥${price}`}}
			</view>
		</view>
		<view class="consult-slogan">
			律师主动联系，专业指导分析
		</view>
		<view class="submit-button-container">
			<button class="submit-button" @click="submitOrder">提交电话咨询</button>
		</view>
		<view class="service-description-container">
			<view class="title">
				服务说明
			</view>
			<view class="service-description-list">
				<view class="service-description-item" v-for="item,index in serviceDescriptionList" :key="index">
					<view class="service-description-title">
						{{item.title}}
					</view>
					<view class="service-description" v-for="citem,cindex in item.childList" :key="cindex">
						{{cindex+1}}、{{citem}}
					</view>
				</view>
			</view>
		</view>
		<!-- 		<view class="bottom-price-bar">
			<view class="price">
				<view class="price-label">
					支付金额：
				</view>
				<view class="price-count">
					￥20.00
				</view>
			</view>
			<u-button class="pay-btn">立即支付</u-button>
		</view> -->
		<payBar ref="payBar" />
	</view>
</template>

<script>
	import topBg from "./components/top-bg/topBg.vue";
	export default {
		components: {
			topBg
		},
		async onLoad(options) {
			this.lawyerId = options.lawyerId;
			const {
				data
			} = await this.$u.post(this.$restUrl.getMobileConsultPrice, {
				model_type: 6
			});
			this.price = data.price;
		},
		data() {
			return {
				price: '',
				lawyerId: '',
				serviceDescriptionList: [{
						title: '服务方式',
						childList: ['客服联系用户和律师，确定见面时间；', '建立专属服务通道，全程提供服务保障；', '律师代理案件，诉讼服务开启。'],
					},
					{
						title: '服务承诺',
						childList: ['小律懂法提供全程服务保障，确保服务质量；', '严格按照隐私保护，绝不向第三方透露您的信息；', '不满意退款，提出申请1个工作日内原路退还款项。'],
					},
					{
						title: '服务流程',
						childList: ['填写案件信息，并完成支付；', '客服联系律师，预约见面时间；', '服务履行，全程跟踪；', '服务完成，对律师服务进行评价。'],
					}
				]
			}
		},
		methods: {
			async submitOrder() {
				const pay_type = await this.getPayType();
				const {
					data
				} = await this.$u.post(this.$restUrl.submitMobileConsultOrder, {
					pay_amount: this.price,
					lid: this.lawyerId,
					pay_type,
				})
				console.log('data>>>>>>>>>>>>>>>>>', data);
				if (pay_type == 1) {
					const options = {
						taskCode: data.task_code,
						price: data.pay_amount,
						countDown: data.expires_time,
						returnUrl: `/pages/order_detail/orderDetail?taskCode=${data.task_code}`
					}
					await this.$refs.payBar.pay(options);
				} else if (pay_type == 2) {
					const res = await this.$u.post(this.$restUrl.getWXPayOptions, {
						task_code: data.task_code,
						amount: data.pay_amount,
					})
					await this.$wx.WXPay({
						...res.data,
						task_code: data.task_code
					});
				}

				console.log('支付成功')
				uni.redirectTo({
					url: `/pages/order_detail/orderDetail?taskCode=${data.task_code}`,
					success: () => {
						uni.showModal({
							title: '下单成功',
							content: '案件分析下单成功，小律懂法工作日将会在30分钟内与您进行联系，请保持登记手机号可正常通话',
							success: (res) => {
								if (res.confirm) {
									console.log('用户点击确认');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./phoneConsult.scss";
</style>
